import type { INovelTag } from "~/types/manage/content/config";
import type {
  IFilter,
  INovel,
  INovelChannelAuth,
  INovelChapter,
} from "~/types/manage/content/novel";
import { request } from "~/utils/http";

export const apiAddNovelTag = (data: Partial<INovelTag>) =>
  request.post("/novel/tags", data);

export const apiModifyNovelTag = (id: number, data: Partial<INovelTag>) =>
  request.put(`/novel/tags/${id}`, data);

export const apiNovelTagAll = (): Promise<INovelTag[]> =>
  request.get("/novel/tags/all");

export const apiModifyNovel = (data: Partial<INovel>) =>
  request.post("/novels", data);

export const apiNovelList = (params: Partial<IFilter>) =>
  request.post("/novels/list", params);

export const apiModifyNovelChapters = (
  novelId: number,
  data: {
    novel: Partial<INovel>;
    chapters: Partial<INovelChapter>[];
  },
) => request.post(`/novels/${novelId}/chapters`, data);

export const apiNovelChapters = (novelId: number): Promise<INovelChapter[]> =>
  request.get(`/novels/${novelId}/chapters`);

export const apiNovelChannelAuth = (novelId: number): Promise<any[]> =>
  request.get(`/novels/channel/auth/${novelId}`);

export const apiSaveNovelChannelAuth = (data: {
  auths: Partial<INovelChannelAuth>[];
}) => request.post(`/novels/channel/auth`, data);
